<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>

<!DOCTYPE html>
<html>
<head>
	<title>未添加药品</title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp"%>
    <!--[if lt IE 9]>
        <script src="lib/js/html5shiv.min.js"></script>
        <script src="lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
    <section class="content-header">
        <h1>添加药品</h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i>首页</a></li>
            <li class="active"><a href="toList.html">采购项目管理</a></li>
            <li class="active"><a href="#">添加药品</a></li>
        </ol>
    </section>
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
                <div class=" form-inline">
                    <div class="form-group form-group-xs">
                     <label>药品编码：</label>
                        <input class="form-control" type="text" id="sdrugCode" placeholder="药品编码" />
                    </div>
                     <div class="form-group form-group-xs">
                        <label>通用名：</label>
                        <input class="form-control" type="text" id="sdrugName" placeholder="通用名" />
                    </div>
                    <div class="form-group form-group-xs">
                        <label>药品分类：</label>
                        <input class="form-control" type="text" id="classify" placeholder="药品分类" />
                    </div>
                    <!-- <div class="form-group form-group-xs">
                        <label for="txtDrugForm">药品分类：</label>
                        <select class="form-control"  id="sbaseDrug" name="status">
                        	<option selected="selected" value="">请选择</option>
                        	<option  value="1">是</option>
                        	<option value="0">否</option>
                        </select>
                    </div> -->
                    <button type="button" class="btn btn-success btn-sm" onclick="search()">查询</button>
                </div>
            </div>
        </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        <div class=" box box-warning bottongroup">
	        <a href="javascript:batchSubmitDrugTOProj();" class="btn btn-default btn-sm">添&nbsp;加</a>
	         <!-- <a href="javascript:checkAddDrug();" class="btn btn-default btn-sm" >已添加药品</a> -->
           <a href="toList.html" class="btn btn-default btn-sm" >返&nbsp;回</a>
        </div>
        <form action="${ctx}/bidProject/toAddedBidProjectDrugsList.html" method="post" id="addDurgFrom">
        <input type="hidden" name="projId" id="projId">
        <input type="hidden" name="projName" id="projName">
        </form>
    </section>
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    <script type="text/javascript">
    
    //查询
	function search() {
		var sdrugCode = $("#sdrugCode").val();
		var sdrugName = $("#sdrugName").val();
		var classify = $("#classify").val();
			$("#gridlist").jqGrid('setGridParam',{
	        datatype:'json',
	        postData:{"qualityspecCode":sdrugCode, "qualityspecName":sdrugName, "qualityspecClass":classify},
	        page : 1
	    }).trigger("reloadGrid"); //重新载入  
	    
	}
        $(function () {
        	 
            $("#gridlist").jqGrid({
                url: "${ctx}/bidProject/getAddDrugDataList.html",
                mtype: "POST",
                postData: { "projId" : "${projId}"},
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: ['药品编码', '通用名','药品分类', '剂型', '规格','操作'],
                colModel: [
                    { name: 'qualityspecCode', width: 100 , align:"center",sortable: false,
                    	formatter:function(cellvalue, options, row){ 
                    		return "<a href=\"javascript:$.HN.dialog.opendialog('"+row.drugCataId+"','药品详情','${ctx}/stdDrug/drugInfoDetail.html?drugId="+row.drugCataId+"','800px','400px',function operResult(val){return operResult;})\">"+cellvalue+"</a>"
                    				}
                    },
                    { name: 'qualityspecName', width: 100 , align:"center" ,sortable: false},
                    { name: 'qualityspecClass', width: 100 , align:"center" ,sortable: false},
                    { name: 'fromName', width: 100 , align:"center" ,sortable: false},
                    { name: 'specName', width: 100 , align:"center" ,sortable: false},
                    { name: 'operate', width: 100 , align:"center",sortable: false, formatter : function(val, opts, rowdata) {
                    	return "<a href='javascript:submitDrugTOProj(JSON.stringify([{\"drugId\":\""+rowdata.drugId+"\",\"projId\":\"${bidProject.projId}\"}]))'>添加</a>";
                    } }
                ],
                
                rowNum: 20,
                rowList: [10, 20, 50, 100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: true, 
                viewrecords: true,
                caption: "${name}-未添加药品",
                jsonReader: {
                    repeatitems: false,
                    id: "drugId"
                }
            });
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            $(window).trigger("resize");
        });

		//批量添加
        function batchSubmitDrugTOProj(){
        	var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];

    		if (rowIds.length <= 0) {
    			$.HN.message.alert("请选择要操作的行！", "消息", "error");
    			return;
    		}
    		var list = [];
    		for (var i=0; i<rowIds.length; i++) {
    			rowId = rowIds[i];
    			var rowData = $("#gridlist").jqGrid('getRowData',rowId);
				list.push({"drugId":rowData.drugCataId,"projId":'${projId}'});
    		}
    		submitDrugTOProj(JSON.stringify(list));
        }
        
        
        //添加
    	function submitDrugTOProj(list){ 
    		$.HN.message.confirm('确定要添加吗？', '', '').on(function (e) {
	               if (e) {
           	$.ajax({
				type:"POST",
				url:"${ctx}/bidProject/batchSubmitDrugTOProj.html",
				data:{"drugs":list},
				dataType:"json",
				success:function(returnData){
					if (returnData.success == true) {
						$("#gridlist").jqGrid("clearGridData");
	    				$("#gridlist").jqGrid().trigger("reloadGrid");
	    				$.HN.message.alert("添加药品成功！", "消息", "success");
	    			} else {
	    				$.HN.message.alert("添加药品失败！", "消息", "error");
	    			}
				}
			});
	               }
          	 });
        	
        }
        
    	function checkAddDrug(){
    		$("#projId").val("${bidProject.projId}");
    		$("#projName").val("${bidProject.name}");
    		$("#addDurgFrom").submit();
    	}
    </script>
</body>
</html>